//
//  MeCircleCell.m
//  CarUser
//
//  Created by 王森林 on 2019/1/23.
//  Copyright © 2019年 王森林. All rights reserved.
//

#import "MeCircleCell.h"

@interface MeCircleCell()
@property (nonatomic, strong) NSDictionary *dataDict;
@property (nonatomic, strong) UIImageView *imgView;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *subTitleLabel;
@property (nonatomic, strong) UIButton *statusBtn;
@property (nonatomic, strong) UILabel *dateLabel;
@property (nonatomic, strong) UIButton *zanBtn;
@property (nonatomic, strong) UIButton *commentBtn;
@end

@implementation MeCircleCell

- (void)createUIWithData
{
    [self.contentView addSubview:self.imgView];
    [self.contentView addSubview:self.titleLabel];
     [self.contentView addSubview:self.subTitleLabel];
     [self.contentView addSubview:self.dateLabel];
     [self.contentView addSubview:self.zanBtn];
    [self.contentView addSubview:self.commentBtn];
    [self.contentView addSubview:self.statusBtn];
    
    
    NSArray *ary = [self.dataDict objectForKey:@"imageList"];
    if (ary != nil && ![ary isKindOfClass:[NSNull class]] && ary.count != 0) {
        NSDictionary *imgDict = ary[0];
        [self.imgView sd_setImageWithURL:[NSURL URLWithString:APPEND_URL(BASE_URL, [imgDict objectForKey:@"TPLJ00"])]];
        
    } else  {
        
        self.imgView.image = IMG(@"me8");
    }
    
//    [self.imgView sd_setImageWithURL:[NSURL URLWithString:APPEND_URL(BASE_URL, [self.dataDict objectForKey:@"headIcon"])]];
    self.titleLabel.text = [self.dataDict objectForKey:@"BT0000"];
    self.subTitleLabel.text = [self.dataDict objectForKey:@"WZNR00"];
    self.dateLabel.text = [self.dataDict objectForKey:@"SJ0000"];
    [self.zanBtn setTitle:[NSString stringWithFormat:@"%@",[self.dataDict objectForKey:@"DZS000"]] forState:UIControlStateNormal];
    NSInteger status = [[NSString stringWithFormat:@"%@",[self.dataDict objectForKey:@"SHZT00"]] intValue];
    if (status == 2) {
         [self.statusBtn setTitle:@"未审核" forState:UIControlStateNormal];
    }
    if (status == 1) {
        [self.statusBtn setTitle:@"已审核" forState:UIControlStateNormal];
    }
   
    [self.imgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(100);
        make.bottom.mas_equalTo(self.contentView.mas_bottom).offset(-10);
        make.left.mas_equalTo(self.contentView.mas_left).offset(15);
        make.top.mas_equalTo(self.contentView.mas_top).offset(10);
    }];
    
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.imgView.mas_right).offset(10);
        make.top.mas_equalTo(self.contentView.mas_top).offset(10);
        make.right.mas_equalTo(self.contentView.mas_right).offset(-15);
        make.height.mas_equalTo(14);
    }];
    [self.subTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.imgView.mas_right).offset(10);
        make.top.mas_equalTo(self.titleLabel.mas_bottom).offset(10);
        make.right.mas_equalTo(self.contentView.mas_right).offset(-15);
        make.height.mas_equalTo(14);
      
    }];
    [self.statusBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.imgView.mas_right).offset(10);
        make.top.mas_equalTo(self.subTitleLabel.mas_bottom).offset(10);
        make.width.mas_equalTo(42);
        make.height.mas_equalTo(18);
    }];
    
    [self.dateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.imgView.mas_right).offset(10);
        make.bottom.mas_equalTo(self.contentView.mas_bottom).offset(-10);
        make.width.mas_equalTo(120);
        make.height.mas_equalTo(14);
    }];
    
    [self.commentBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.contentView.mas_right).offset(-10);
        make.bottom.mas_equalTo(self.contentView.mas_bottom).offset(-10);
        make.width.mas_equalTo(20);
        make.height.mas_equalTo(15);
    }];
    
    [self.zanBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.commentBtn.mas_left).offset(-10);
        make.bottom.mas_equalTo(self.contentView.mas_bottom).offset(-10);
        make.width.mas_equalTo(40);
        make.height.mas_equalTo(15);
    }];
    
}

- (void)setData:(id)data
{
    self.dataDict = [NSDictionary dictionaryWithDictionary:data];
    [self createUIWithData];
    
}

-  (UILabel *)titleLabel
{
    if (!_titleLabel) {
        _titleLabel = [UILabel new];
        _titleLabel.numberOfLines = 0;
        _titleLabel.textColor = Common_TextColor;
        _titleLabel.font = FONT_SIZE(15);
    }
    return _titleLabel;
    
}

- (UIImageView *)imgView
{
    
    if (!_imgView) {
        _imgView = [UIImageView new];
        _imgView.contentMode = UIViewContentModeScaleToFill;
        _imgView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
    }
    return _imgView;
}

-  (UILabel *)dateLabel
{
    if (!_dateLabel) {
        _dateLabel = [UILabel new];
        _dateLabel.textColor = Common_TextLowColor;
        _dateLabel.font = FONT_SIZE(11);
    }
    return _dateLabel;
    
}
-  (UILabel *)subTitleLabel
{
    if (!_subTitleLabel) {
        _subTitleLabel = [UILabel new];
        _subTitleLabel.textColor = Common_TextLowColor;
        _subTitleLabel.font = FONT_SIZE(11);
    }
    return _subTitleLabel;
    
}
- (UIButton *)zanBtn
{
    if (!_zanBtn) {
        _zanBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_zanBtn setImage:IMG(@"circle1") forState:UIControlStateNormal];
        [_zanBtn setTitle:@"2" forState:UIControlStateNormal];
        [_zanBtn setTitleColor:Common_TextColor forState:UIControlStateNormal];
        _zanBtn.titleLabel.font = FONT_SIZE(10);
        [_zanBtn setTitleEdgeInsets:UIEdgeInsetsMake(0 ,0, 0.0,-10)];//文字距离上边框的距离增加imageView的高度，距离左边框减少imageView的宽度，距离下边框和右边框距离不变
        [_zanBtn setImageEdgeInsets:UIEdgeInsetsMake( 0, 0,0.0, 0)];//
    }
    return _zanBtn;
    
}
- (UIButton *)statusBtn
{
    if (!_statusBtn) {
        _statusBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _statusBtn.layer.cornerRadius = 5;
        _statusBtn.layer.masksToBounds = YES;
        _statusBtn.layer.borderColor = Common_Head_Color.CGColor;
        _statusBtn.layer.borderWidth = 1;
        _statusBtn.titleLabel.font = FONT_SIZE(10);
        [_statusBtn setTitleColor:Common_Text_TextfieldColor forState:UIControlStateNormal];
//        _statusBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    }
    return _statusBtn;
    
}



- (UIButton *)commentBtn
{
    if (!_commentBtn) {
        _commentBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_commentBtn setImage:IMG(@"circle2") forState:UIControlStateNormal];
    }
    return _commentBtn;
    
}

@end
